|
ARD2
RC2
Airbag Reference Demonstrator using MPC5604P
|
00001 00016 #include "derivative.h" 00017 #include "SIU.h" 00018 /* 00019 ****************************************************************************** 00020 * Constants 00021 ****************************************************************************** 00022 */ 00023 /* 00024 ****************************************************************************** 00025 * Globals 00026 ****************************************************************************** 00027 */ 00028 /* 00029 ****************************************************************************** 00030 * vfnConfigDefaultPinBehavior 00031 ****************************************************************************** 00032 */ 00033 void vfnConfigDefaultPinBehavior(const uint16_t* pu16Config, uint8_t u8Offset, \ 00034 uint8_t u8ConfigSize) 00035 { 00036 /* Local variables */ 00037 uint8_t u8Counter; 00038 00039 /* Make sure Pin is not higher than max available */ 00040 if(PIN_CONFIG_REGISTER_MAX < (u8ConfigSize + u8Offset)) 00041 { 00042 u8ConfigSize = PIN_CONFIG_REGISTER_MAX - u8Offset; 00043 } 00044 else 00045 { 00046 /* Proceed */ 00047 } 00048 00049 for(u8Counter = CLEAR; u8Counter < u8ConfigSize; u8Counter++) 00050 { 00051 SIU.PCR[u8Counter + u8Offset].R = *pu16Config; 00052 pu16Config++; 00053 } 00054 00055 return; 00056 } 00057 /* 00058 ****************************************************************************** 00059 * vfnToggleOutputPin 00060 ****************************************************************************** 00061 */ 00062 void vfnToggleOutputPin(const uint8_t u8Port, const uint8_t u8Pin, \ 00063 const uint8_t u8Level) 00064 { 00065 SIU.GPDO[u8fnReturnPinIndex(u8Port, u8Pin)].B.PDO = (CLEAR < u8Level); 00066 00067 return; 00068 } 00069 /* 00070 ****************************************************************************** 00071 * u8fnReadPin 00072 ****************************************************************************** 00073 */ 00074 uint8_t u8fnReadPin(const uint8_t u8Port, const uint8_t u8Pin) 00075 { 00076 uint8_t u8PCRPinIndex; 00077 uint8_t u8PinLevel; 00078 00079 /* Figure out what the index is for PCR */ 00080 u8PCRPinIndex = u8fnReturnPinIndex(u8Port, u8Pin); 00081 u8PinLevel = SIU_INVALID_PIN_CONFIGURATION; 00082 00083 /* Depending on configuration (input, output), return value */ 00084 if(TRUE == SIU.PCR[u8PCRPinIndex].B.IBE) 00085 { 00086 /* If configured for input, read input register */ 00087 u8PinLevel = SIU.GPDI[u8PCRPinIndex].B.PDI; 00088 } 00089 else if(TRUE == SIU.PCR[u8PCRPinIndex].B.OBE) 00090 { 00091 /* Else, if configured as output, read output register */ 00092 u8PinLevel = SIU.GPDO[u8PCRPinIndex].B.PDO; 00093 } 00094 else 00095 { 00096 /* Don't do anything - we will return an error */ 00097 } 00098 00099 return(u8PinLevel); 00100 } 00101 /* 00102 ****************************************************************************** 00103 * u8fnReturnPinIndex 00104 ****************************************************************************** 00105 */ 00106 uint8_t u8fnReturnPinIndex(const uint8_t u8Port, const uint8_t u8Pin) 00107 { 00108 /* Quick version */ 00109 return((uint8_t)((u8Port - 'A') * N_PINS_PER_PORT) + u8Pin); 00110 } 00111 /* 00112 ****************************************************************************** 00113 * u8fnRouteInputPad 00114 ****************************************************************************** 00115 */ 00116 uint8_t u8fnRouteInputPad(const uint8_t u8Module, const uint8_t u8PinIndex) 00117 { 00118 uint8_t u8Status; 00119 00120 u8Status = PAD_DOES_NOT_EXIST; 00121 00122 if(N_INPUT_PADS > u8Module) 00123 { 00124 SIU.PSMI[u8Module].B.PADSEL = u8PinIndex; 00125 u8Status = CLEAR; 00126 } 00127 else 00128 { 00129 /* Get out */ 00130 } 00131 00132 return(u8Status); 00133 } 00134 /* 00135 ****************************************************************************** 00136 * u8fnIRQConfig 00137 ****************************************************************************** 00138 */ 00139 uint8_t u8fnIRQConfig(uint8_t u8Channel, IRQConfig_t tConfig) 00140 { 00141 uint8_t u8Status; 00142 uint32_t u32ChannelMask; 00143 00144 u8Status = CLEAR; 00145 00146 /* All operations are performed through a mask to the channel */ 00147 /* First of all, let's generate the mask */ 00148 u32ChannelMask = BIT0 << u8Channel; 00149 00150 /* We will now clear any pre-existing conditions */ 00151 SIU.ISR.R |= u32ChannelMask; 00152 00153 /* Next we set config for falling and raising edge based on config. */ 00154 if(CLEAR == tConfig.P.FallingEdgeEn) 00155 { 00156 SIU.IFEER.R &= (~u32ChannelMask); 00157 } 00158 else 00159 { 00160 SIU.IFEER.R |= (u32ChannelMask); 00161 } 00162 if(CLEAR == tConfig.P.RisingEdgeEn) 00163 { 00164 SIU.IREER.R &= (~u32ChannelMask); 00165 } 00166 else 00167 { 00168 SIU.IREER.R |= (u32ChannelMask); 00169 } 00170 00171 /* Repeat the operation for the glitch filter */ 00172 if(CLEAR == tConfig.P.GlitchFiltEn) 00173 { 00174 SIU.IFER.R &= (~u32ChannelMask); 00175 } 00176 else 00177 { 00178 SIU.IFER.R |= (u32ChannelMask); 00179 } 00180 00181 /* Finally we set the IRQ enable based on config as well */ 00182 if(CLEAR == tConfig.P.IRQEn) 00183 { 00184 SIU.IRER.R &= (~u32ChannelMask); 00185 } 00186 else 00187 { 00188 SIU.IRER.R |= (u32ChannelMask); 00189 } 00190 00191 return(u8Status); 00192 } 00193 /* 00194 ****************************************************************************** 00195 * vfnIRQClearIsr 00196 ****************************************************************************** 00197 */ 00198 void vfnIRQClearIsrFlag(uint8_t u8Channel) 00199 { 00200 SIU.ISR.R |= (BIT0 << u8Channel); 00201 00202 return; 00203 } 00204 /* 00205 ****************************************************************************** 00206 * 00207 * End of file. 00208 * 00209 ****************************************************************************** 00210 */